package com.mall.b2c.hessian.impl;

import com.mall.b2c.domain.car.CarDomain;
import com.mall.b2c.domain.card.CardDomain;
import com.mall.b2c.hessian.CardHessian;
import com.mall.b2c.hessian.IntergralHessian;
import com.mall.b2c.service.CarService;
import com.mall.b2c.service.CardService;
import com.mall.b2c.service.IntergralOrderService;
import com.mall.b2c.service.IntergralService;
import com.mall.common.bean.Message;
import com.mall.common.exception.NoticeException;
import com.mall.common.hessian.BaseHessian;
import com.mall.common.hessian.impl.BaseHessianImpl;
import com.mall.common.service.PaymentLogService;
import com.mall.common.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;

@Service("b2cCardHessian")
public class CardHessianImpl extends BaseHessianImpl implements CardHessian {

    @Resource
    IntergralService intergralService;
    @Resource
    private CarService carService;

    @Resource
    PaymentLogService paymentLogService;

    @Resource
    CardService cardService;


    public String cardsubmit(Long account, String password, Long memberId) {

        CardDomain cardDomain = cardService.find((account - 100000000000L));
        if (cardDomain == null) {
            throw new NoticeException("请输入正确卡号,密码");
        }

        Message message = cardService.docardsubmit(cardDomain, password, memberId);
        if (message.getType().toString().equals("SUCCESS")) {
            return "1";
        } else {
            return "0";
        }


    }


    @Override
    public void carAdd(String city, String carNo, String year, String month, Double price, String mobile) {
        CarDomain car = new CarDomain();
        car.setCarNo(carNo);
        car.setCity(city);
        car.setPrice(BigDecimal.valueOf(price));
        car.setHasCarNo(StringUtils.isNotBlank(carNo));
        car.setMobile(mobile);
        try {
            car.setBuyDate(DateUtils.parseDate(year + "-" + month, "yyyy-MM"));
        }catch (Exception e){
            throw new NoticeException("年月格式不正确");
        }
        carService.persist(car);
    }
}
